﻿using Newtonsoft.Json;
using System;

namespace Common.DataModels;
/// <summary>
/// 基础实体(记录一些公共的字段)
/// </summary>
public abstract class BaseEntity<T>:AggregateRoot where T:class
{
    /// <summary>
    /// 是否删除
    /// </summary>
    [JsonProperty]
    public bool IsDelete { get; protected set; }
    /// <summary>
    /// 创建时间
    /// </summary>
    [JsonProperty]
    public DateTime CreationTime { get; protected set; }
    /// <summary>
    /// 修改时间
    /// </summary>
    [JsonProperty]
    public DateTime ModificationTime { get; protected set; }
    /// <summary>
    /// 创建人
    /// </summary>
    [JsonProperty]
    public long Creator { get; protected set; }
    /// <summary>
    /// 修改人
    /// </summary>
    [JsonProperty]
    public long Modifier { get; protected set; }
    /// <summary>
    /// 初始化参数
    /// </summary>
    /// <param name="creatorId"></param>
    protected void Init(long creatorId)
    {
        base.Id = SnowflakeHelper.GetId();
        this.IsDelete = false;
        this.CreationTime = DateTime.Now;
        this.ModificationTime = DateTime.Now;
        this.Creator = creatorId;
        this.Modifier = creatorId;
    }


    /// <summary>
    /// 构造对象的方法  必须实现  用来初始化对象的一些基本信息
    /// </summary>
    /// <param name="creatorId"></param>
    /// <returns></returns>
    public abstract T Build(long creatorId = 0);

}